/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extension.game.poker;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import log.Debug;

/**
 *
 * @author daz
 */
public class SitOutHandler extends BaseClientRequestHandler {

    @Override
    public void handleClientRequest(User user, ISFSObject params) {
        int pos = params.getInt("sit_out_pos");
        int state = params.getInt("sit_out_state");
        Debug.line("receive sit out");
        Debug.d(user.getName() + " sit out pos:" + pos);
        Debug.d(user.getName() + " sit out state:" + state);
        PokerRoomExtension pokerRoomExtension = (PokerRoomExtension) getParentExtension();
        PokerGame pokerGame = pokerRoomExtension.getPokerGame();
        Response response = pokerRoomExtension.getResponse();
        if (state == 0) {
            response.sendSitOutState(params, pokerRoomExtension.getParentRoom().getPlayersList());
            pokerGame.sitOut(user);
            if (pos == pokerGame.getBettingTurn()) {
                pokerGame.nextTurn();
            }
        } else {
            response.sendSitOutState(params, pokerRoomExtension.getParentRoom().getPlayersList());
            pokerGame.finishSitOut(user);
        }
        pokerRoomExtension.getResponse().sendMessageChat(user.getName() + " không chơi", 0);
    }
}
